package de.klingbeil.hhc.testhelper.impl;

import static org.mockito.Mockito.mock;

import java.util.HashMap;
import java.util.Map;

import com.google.web.bindery.requestfactory.shared.ServiceLocator;

public class MockingServiceLocator implements ServiceLocator {
	private final Map<Class<?>, Object> registry;

	public MockingServiceLocator() {
		this.registry = new HashMap<Class<?>, Object>();
	}

	@Override
	public Object getInstance(Class<?> clazz) {
		Object result = registry.get(clazz);
		if (result == null) {
			result = mock(clazz);
			registry.put(clazz, result);
		}
		return result;
	}
}